﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hegang_winform.dao.impl
{
    class Felec : DataSaveObject
    {
        public void save(DbObject o, ref DbServiceInput input)
        {
            string str = "SELECT COUNT(id) FROM `felec`;";
            DataTable dt = o.cmdHasReturn(str);
            int row_num = Convert.ToInt32(dt.Rows[0][0]);

            string time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string str_save = string.Format("INSERT INTO `felec` (`lici`,`dianshu`,`timeStamp`) VALUES ( '{0}','{1}','{2}');", input.Dic["副井.副提升电控.励磁电流"], input.Dic["副井.副提升电控.电枢电流"], time);
            string str_del = "DELETE FROM felec WHERE id=(SELECT MIN(id) FROM `felec`);";

            if (row_num == 10)
            {
                o.cmdNoReturn(str_del);
                o.cmdNoReturn(str_save);
            }
            else if (row_num < 10)
            {
                o.cmdNoReturn(str_save);
            }
            else
            {
                for (int i = 0; i < row_num - 10; i++)
                    o.cmdNoReturn(str_del);
            }
        }
    }
}
